package com.zzhardy.controller.admin.permission.controller;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.zzhardy.common.model.ResultResponse;
import com.zzhardy.controller.admin.permission.model.SysMenu;
import com.zzhardy.controller.admin.permission.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 文章分类
 *
 * @author Hardy
 */
@Controller
@RequestMapping("/permission/data/")
public class SysPermissionDataController {
    private int            uid    = 10;
    private int            unitId = 100;
    private int            sysId = 100;
    @Autowired
    private SysMenuService sysMenuService;
    
    /**
     * 新增或修改菜单
     */
    @PostMapping(value = "addOrUpdateMenu")
    @ResponseBody
    public ResultResponse addOrUpdateMenu(@RequestBody SysMenu sysMenu,
                                          HttpServletRequest request,
                                          ModelMap modelMap) {
        return sysMenuService.saveOrUpdateMenu(sysMenu, uid, unitId, sysId);
      
    }
    
    /**
     * 获取菜单树
     */
    @PostMapping(value = "getMenuTree")
    @ResponseBody
    public ResultResponse getMenuTree() {
        List<SysMenu> menuData = sysMenuService.getAllMenuByUnitIdAndSysId(unitId, sysId);
        return ResultResponse.success(menuData);
      
    }
    
    /**
     * 获取菜单树
     */
    @PostMapping(value = "batchDeleteMenu")
    @ResponseBody
    public ResultResponse batchDeleteMenu(@RequestParam(value = "ids", required = false) String ids, HttpServletRequest request) {
        sysMenuService.batchDeleteMenu(ids, uid);
        return ResultResponse.success("删除成功！");
      
    }
}
